package com.zkingsoft.actions.admin;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.dao.SendReportDao;
import com.zkingsoft.model.ProjUser;
import com.zkingsoft.model.Project;
import com.zkingsoft.model.Report;
import com.zkingsoft.model.SendReport;
import com.zkingsoft.model.Users;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.ProjUserService;
import com.zkingsoft.services.ProjectService;
import com.zkingsoft.services.ReportService;
import com.zkingsoft.services.SendReportService;
import com.zkingsoft.services.UsersService;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-11 10:23
 */
@Controller
@RequestMapping(value = "/admin/report")
public class ReportController extends BaseController{

	@Resource
	private ReportService currentService;
	@Resource
	private ProjectService projectService;
	@Resource
	private UsersService usersService;
	@Resource
	private SendReportService sendReportService;
	
	/**
	 *进入页面
	 */
	@RequestMapping(value = "/report")
	public String all(Long id) {
		if(id != null){
			WebUtil.getRequest().setAttribute("obj", projectService.findById(id));
		}
		return "admin/report-list";
	}
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(Report report, PaginationVO pageVo) {
		report.setSendId(getMe().getId());//我发送的
		return showList(currentService, report, pageVo);
	}
	
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Report report) {
		if (report.getId() != null) {
			return modify(currentService, report, "总结文档");
		} else {
			report.setCommitTime(new Date());
			report.setSendId(getMe().getId());
			return add(currentService, report, "总结文档");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id,Long projId) {
		Report report;
		if (id != null) {
			report = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", report);
		}
		if(projId != null){
			WebUtil.getRequest().setAttribute("projId", projId);
		}
		
		
		return "admin/report-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
 	
 	
 	//接收人查询
 	@RequestMapping(value = "/queryUserName")
	public @ResponseBody AjaxResult queryProjUserName() {
		Users users=new Users();
		users.setUserType(Dictionary.USER_TYPE_EMPLOYEE);
		users.setIsDeleted(Dictionary.DELETED_N);
		return new AjaxResult(AjaxResult.STATUS_OK, null,null,usersService.findByModel(users),0);
 	}
 	//收件人查询
 	@RequestMapping(value = "/querySendReport")
	public @ResponseBody AjaxResult querySendReport(SendReport sendReport) {
		return new AjaxResult(AjaxResult.STATUS_OK, null,null,sendReportService.findByModel(sendReport),0);
 	}
}